import * as actionTypes from './actionTypes'
import { fromJS } from 'immutable'
const defaultState = fromJS({
  focus: false,
  enter: false,
  list: [],
  page: 1,
  totalPage: 1
})

export default (state = defaultState, action) => {
  switch (action.type) {
    case actionTypes.CHANGE_TO_FOCUS:
      return state.set('focus', true)
    case actionTypes.CHANGE_TO_BLUR:
      return state.set('focus', false)
    case actionTypes.CHANGE_SEARCH_LIST:
      return state.merge({
        list: action.data,
        totalPage: action.totalPage
      })
    case actionTypes.CHANGE_TO_ENTER:
      return state.set('enter', true)
    case actionTypes.CHANGE_TO_LEAVE:
      return state.set('enter', false)
    case actionTypes.CHANGE_PAGE:
      return state.set('page', action.page)
    default:
      return state
  }
}
